<template>
    <div class="top-container">
        <el-form :model="searchForm">
            <el-row>
                <el-form-item label="文件名称" label-width="100px">
                    <el-input v-model="searchForm.file_name" autocomplete="off"></el-input>
                </el-form-item>
            </el-row>
            <el-row type="flex">
                <el-col>
                    <el-form-item label="上传时间" label-width="100px">
                        <el-date-picker
                                v-model="searchForm.dateRange"
                                type="daterange"
                                align="right"
                                unlink-panels
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                value-format="yyyy-MM-dd"
                                :picker-options="pickerOptions">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :sm="12" :lg="9" :xl="7">
                    <el-form-item label="是否上传结束" label-width="100px">
                        <el-select v-model="searchForm.is_end" :clearable="true">
                            <el-option :label="item" :value="index"  v-for="(item,index) in collectionData.YESORNO"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :sm="3" :lg="1" :xl="2">
                    <el-button type="primary" @click="handleQueryInfo">查询</el-button>
                </el-col>
            </el-row>

        </el-form>
        <el-table :data="infoGridData">
            <el-table-column property="file_name" label="文件名称" width="200"></el-table-column>
            <el-table-column property="progress" label="步骤" width="80">
                <template slot-scope="scope">
                    {{collectionData.steps[scope.row.progress]}}
                </template>
            </el-table-column>
            <el-table-column property="storeProgress" label="存储进度"></el-table-column>
            <el-table-column property="is_end" label="是否结束" width="80">
                <template slot-scope="scope">
                    {{collectionData.steps[scope.row.progress]}}
                </template>
            </el-table-column>
            <el-table-column property="beginDate" label="上传时间" width="140"></el-table-column>
            <el-table-column property="endDate" label="完成时间" width="140"></el-table-column>
            <el-table-column label="错误信息" fixed="right" width="100">
                <template slot-scope="scope">
                    <el-popover v-if="typeof scope.row.errorinfo == 'string' && scope.row.errorinfo.length > 0"
                                width="600"
                                title="错误详情"
                                placement="right-end"
                                popper-class="define-popover"
                                trigger="click"
                                :content="scope.row.errorinfo">
                        <el-button slot="reference" icon="el-icon-view"></el-button>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column label="历史处理信息下载" fixed="right" width="130">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-download" style="color: red" @click.prevent="handleDownloadHistoryDeal(scope.row,dataSign.error)">
                        导出失败信息
                    </el-button>
                    <br/>
                    <el-button type="text" icon="el-icon-download" style="color: green" @click.prevent="handleDownloadHistoryDeal(scope.row,dataSign.success)">
                        导出成功信息
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "fileImportHistory",
        props:['collectionData','dataSign','access_token'],
        data() {
            return {
                //信息查询表格
                searchForm:{
                    file_name:'',
                    is_end:'',
                    dateRange:''
                },
                infoGridData:[],
                //日期快捷查询配置
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
            }
        },
        methods:{
            handleQueryInfo(){
                let formData = this.searchForm;
                let submitData = {
                    file_name : formData.file_name,
                    is_end : formData.is_end,
                    date1 : formData.dateRange && formData.dateRange[0] || '',
                    date2 : formData.dateRange && formData.dateRange[1] || ''
                }
                this.Base.submit(this,this.access_token,{
                    url:'/fileImport/fileImportController!getFileImport.do',
                    formData : submitData
                },(data)=>{
                    this.infoGridData = (data.lists && data.lists.fileGrid1 && data.lists.fileGrid1.list) || []
                },(error)=>{
                    //todo 消息提示
                    this.infoGridData = []
                })
            },
            handleDownloadHistoryDeal(row,dataSign){
                //dataSign 1成功 2失败
                this.$emit("toDownload",row.uploadGuid+row.file_name,dataSign,row.file_name)
            }
        }
    }
</script>
<style>

</style>